package com.socialrss.accounts.factoryobject;

import android.content.ContentValues;
import android.database.Cursor;
import android.util.Log;

import com.socialrss.accounts.AbstractHolder;
import com.socialrss.accounts.Group;
import com.socialrss.accounts.dbinterfaces.ConnectionTable;
import com.socialrss.accounts.dbinterfaces.GroupTable;

public class GroupFactory extends AbstractHolderFactory {

	@Override
	public AbstractHolder turnToObj(Cursor cur) {
		Group temp  = new Group(cur.getInt(0), cur.getString(1), cur.getInt(2));
		if(cur.getString(3) != null){
			temp.setParentId(cur.getInt(3));
		}
		return temp;
	}

	@Override
	public ContentValues tunToDBInput(AbstractHolder abs) {
		ContentValues values = new ContentValues();
		values.put(GroupTable.NAME, abs.getName());
		values.put(GroupTable.SELECTED, abs.isTurnedOn());
		return values;
	}

	@Override
	public ContentValues turnToPartialDBInput(AbstractHolder abs,
			String... columns) {
		ContentValues values = new ContentValues();
		for (int i = 0; i < columns.length; i++) {
			if(columns[i].equals(GroupTable.NAME))
				values.put(GroupTable.NAME, abs.getName());
			else if(columns[i].equals(ConnectionTable.SELECTED))
				values.put(GroupTable.SELECTED, abs.isTurnedOn());
		}
		return values;
	}

}
